package com.ycy.variable;

import com.ycy.BaseNoListenerTest;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.ycy.RdfaBpCustomVarContants.TASK_OPERATE_TYPE;

/**
 *
 */
public class UserTaskToGateway extends BaseNoListenerTest {

  @Test
  public void create() {
    Deployment deploy = repositoryService.createDeployment().addClasspathResource("variable/abcdef.bpmn20.xml").deploy();
    System.out.println(deploy.getId());
    //设置流程变量
    HashMap<String, Object> map = new HashMap<>();
    //定义的人员列表4人
    String[] v = {"shareniu1", "shareniu2", "shareniu3", "shareniu4"};
    map.put("assigneeList_B", Arrays.asList(v));
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("passAndReject", map);
    System.out.println("==> 流程实例启动 实例id :" + pi.getProcessInstanceId());
    //7504
  }

  @Test
  public void query() {
    List<Task> list1 = taskService.createTaskQuery().processInstanceId("167504").list();
    for (Task task : list1) {
      System.out.println(task);
      Map<String, Object> variables = taskService.getVariables(task.getId());
      System.out.println(variables);
    }
  }

  String ataskId = "165004";

  @Test
  public void passB() {
    HashMap<String, Object> variables = new HashMap<>();
    String[] v = {"shareniu1", "shareniu2", "shareniu3", "shareniu4"};
    variables.put("assigneeList_C", Arrays.asList(v));
    variables.put("commnet", "作为b组老大，我说可以通过");
    taskService.complete(ataskId, variables);
  }

  @Test
  public void pass() {
    HashMap<String, Object> variables = new HashMap<>();
    variables.put("commnet", "作为C组老大，我说可以通过");
    variables.put("approved", true);
    taskService.complete("157529", variables);
  }

}
